package practice1_100;

public class Practice680 {
    public  int chance=1;
    public boolean validPalindrome(String s) {
        int left   =0,right=s.length()-1;
        int chance=1;
        while (left<=right){
            if(s.charAt(left)!=s.charAt(right)&&chance<=0){
                //System.out.println(left);
                return false;
            }else if(chance==1&&s.charAt(left)!=s.charAt(right)){
                if(s.charAt(left+1)==s.charAt(right)||s.charAt(left)==s.charAt(right-1)){
                    chance--;
                    left++;
                }else if(s.charAt(left)==s.charAt(right-1)){
                    chance--;
                    right--;
                }else {
                    return false;
                }
            }
            left++;
            right--;
        }
        return true;
    }
    public boolean validPalindrome111(String s) {
        int left=0,right=s.length()-1;
        return dp(s,left,right);

    }
    public boolean  dp(String s,int left ,int right) {
        if(left>right) return true;
        if(s.charAt(left)!=s.charAt(right)&&chance<=0){
            return false;
        }else if(chance==1&&s.charAt(left)!=s.charAt(right)){
            if(s.charAt(left+1)==s.charAt(right)||s.charAt(left)==s.charAt(right-1)){
                chance--;
                return dp(s,left+1,right)||dp(s,left,right-1);
            }else {
                return false;
            }
        }
        return dp(s,left+1,right-1);

    }

    public static void main(String[] args) {
        boolean a=new Practice680().validPalindrome111("cupuupucu");
        System.out.println(a);
    }
}
